//
//  SquareDetailsQuote.m
//
//  Created by lianchuang  on 14-12-17
//  Copyright (c) 2014 __MyCompanyName__. All rights reserved.
//

#import "SquareDetailsQuote.h"


NSString *const kSquareDetailsQuoteSenduid = @"senduid";
NSString *const kSquareDetailsQuoteDateline = @"dateline";
NSString *const kSquareDetailsQuotePcid = @"pcid";
NSString *const kSquareDetailsQuoteMessage = @"message";
NSString *const kSquareDetailsQuoteSendusername = @"sendusername";
NSString *const kSquareDetailsQuoteRecvusername = @"recvusername";
NSString *const kSquareDetailsQuoteUpid = @"upid";
NSString *const kSquareDetailsQuoteUseip = @"useip";
NSString *const kSquareDetailsQuoteRecvuid = @"recvuid";
NSString *const kSquareDetailsQuotePid = @"pid";


@interface SquareDetailsQuote ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation SquareDetailsQuote

@synthesize senduid = _senduid;
@synthesize dateline = _dateline;
@synthesize pcid = _pcid;
@synthesize message = _message;
@synthesize sendusername = _sendusername;
@synthesize recvusername = _recvusername;
@synthesize upid = _upid;
@synthesize useip = _useip;
@synthesize recvuid = _recvuid;
@synthesize pid = _pid;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.senduid = [self objectOrNilForKey:kSquareDetailsQuoteSenduid fromDictionary:dict];
            self.dateline = [self objectOrNilForKey:kSquareDetailsQuoteDateline fromDictionary:dict];
            self.pcid = [self objectOrNilForKey:kSquareDetailsQuotePcid fromDictionary:dict];
            self.message = [self objectOrNilForKey:kSquareDetailsQuoteMessage fromDictionary:dict];
            self.sendusername = [self objectOrNilForKey:kSquareDetailsQuoteSendusername fromDictionary:dict];
            self.recvusername = [self objectOrNilForKey:kSquareDetailsQuoteRecvusername fromDictionary:dict];
            self.upid = [self objectOrNilForKey:kSquareDetailsQuoteUpid fromDictionary:dict];
            self.useip = [self objectOrNilForKey:kSquareDetailsQuoteUseip fromDictionary:dict];
            self.recvuid = [self objectOrNilForKey:kSquareDetailsQuoteRecvuid fromDictionary:dict];
            self.pid = [self objectOrNilForKey:kSquareDetailsQuotePid fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.senduid forKey:kSquareDetailsQuoteSenduid];
    [mutableDict setValue:self.dateline forKey:kSquareDetailsQuoteDateline];
    [mutableDict setValue:self.pcid forKey:kSquareDetailsQuotePcid];
    [mutableDict setValue:self.message forKey:kSquareDetailsQuoteMessage];
    [mutableDict setValue:self.sendusername forKey:kSquareDetailsQuoteSendusername];
    [mutableDict setValue:self.recvusername forKey:kSquareDetailsQuoteRecvusername];
    [mutableDict setValue:self.upid forKey:kSquareDetailsQuoteUpid];
    [mutableDict setValue:self.useip forKey:kSquareDetailsQuoteUseip];
    [mutableDict setValue:self.recvuid forKey:kSquareDetailsQuoteRecvuid];
    [mutableDict setValue:self.pid forKey:kSquareDetailsQuotePid];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.senduid = [aDecoder decodeObjectForKey:kSquareDetailsQuoteSenduid];
    self.dateline = [aDecoder decodeObjectForKey:kSquareDetailsQuoteDateline];
    self.pcid = [aDecoder decodeObjectForKey:kSquareDetailsQuotePcid];
    self.message = [aDecoder decodeObjectForKey:kSquareDetailsQuoteMessage];
    self.sendusername = [aDecoder decodeObjectForKey:kSquareDetailsQuoteSendusername];
    self.recvusername = [aDecoder decodeObjectForKey:kSquareDetailsQuoteRecvusername];
    self.upid = [aDecoder decodeObjectForKey:kSquareDetailsQuoteUpid];
    self.useip = [aDecoder decodeObjectForKey:kSquareDetailsQuoteUseip];
    self.recvuid = [aDecoder decodeObjectForKey:kSquareDetailsQuoteRecvuid];
    self.pid = [aDecoder decodeObjectForKey:kSquareDetailsQuotePid];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_senduid forKey:kSquareDetailsQuoteSenduid];
    [aCoder encodeObject:_dateline forKey:kSquareDetailsQuoteDateline];
    [aCoder encodeObject:_pcid forKey:kSquareDetailsQuotePcid];
    [aCoder encodeObject:_message forKey:kSquareDetailsQuoteMessage];
    [aCoder encodeObject:_sendusername forKey:kSquareDetailsQuoteSendusername];
    [aCoder encodeObject:_recvusername forKey:kSquareDetailsQuoteRecvusername];
    [aCoder encodeObject:_upid forKey:kSquareDetailsQuoteUpid];
    [aCoder encodeObject:_useip forKey:kSquareDetailsQuoteUseip];
    [aCoder encodeObject:_recvuid forKey:kSquareDetailsQuoteRecvuid];
    [aCoder encodeObject:_pid forKey:kSquareDetailsQuotePid];
}

- (id)copyWithZone:(NSZone *)zone
{
    SquareDetailsQuote *copy = [[SquareDetailsQuote alloc] init];
    
    if (copy) {

        copy.senduid = [self.senduid copyWithZone:zone];
        copy.dateline = [self.dateline copyWithZone:zone];
        copy.pcid = [self.pcid copyWithZone:zone];
        copy.message = [self.message copyWithZone:zone];
        copy.sendusername = [self.sendusername copyWithZone:zone];
        copy.recvusername = [self.recvusername copyWithZone:zone];
        copy.upid = [self.upid copyWithZone:zone];
        copy.useip = [self.useip copyWithZone:zone];
        copy.recvuid = [self.recvuid copyWithZone:zone];
        copy.pid = [self.pid copyWithZone:zone];
    }
    
    return copy;
}


@end
